package com.qf.rabbitMQ.listener;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 郗昊天
 * @version 1.0
 * @package com.qf.rabbitMQ.listener
 * @date 2022/10/15 9:59
 */
@Component
public class Mqlistener {

    @RabbitListener(queues = {"xht"})
    public void onMessage(String msg, Channel channel, Message message){
        System.out.println("springboot收到了消息" + msg);
        try {
            //手动 应答
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @RabbitListener(queues = {"fanoutQueue04"})
    public void onMessage1(String msg){
        System.out.println("springboot111收到了消息" + msg);
    }
}
